import ioIndex from './index'

/**
 * promiseIo类
 *
 * @description 继承原有的 io模块
 * @property io 原有定义的io模块输出的，可以拿到原有的接口
 * @method  post 在原有io.post加了promise,方便用async awit
 * @method  get 在原有io.get加了promise,方便用async awit
 */
class promiseIo {
  get io() {
    return ioIndex
  }
  post(url, data) {
    return new Promise((resolve, reject) => {
      ioIndex.post(url, data, function (res) {
        if (res.success) {
          resolve(res)
        } else {
          reject(res)
        }
      }, function (xhr, status, error) {
        throw new Error(xhr);
      })
    })
  }
  get(url, data) {
    return new Promise((resolve, reject) => {
      ioIndex.post(url, data, function (res) {
        if (res.success) {
          resolve(res)
        } else {
          reject(res)
        }
      }, function (xhr, status, error) {
        throw new Error(xhr);
      })
    })
  }
}



export let io = ioIndex
export let newProIo = new promiseIo()
